package com.itheima.redbaby.factory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * dao,engine工厂
 * 
 * @author l
 * 
 */
public class DaoAndEngineFactory {
	private static Properties properties;

	static {
		properties = new Properties();
		InputStream is = DaoAndEngineFactory.class.getClassLoader().getResourceAsStream("factory.properties");
		try {
			properties.load(is);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 依据配置文件加载对象
	 * @return
	 */
	public static<T> T getImpl(Class<T> clazz) {
//		clazz.getName();
		String key = clazz.getSimpleName();//"UserEngine";
		String value = properties.getProperty(key);
		try {
			return (T) Class.forName(value).newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
